﻿using System.Collections.Generic;
using System.Data;
using dk2Database;
using dk2Database.Commands;
using dk2Repository.Example.BL;

namespace dk2Repository.Example.DAL
{
    
    class SelectUserCommand : QueryEntityCommandBase<List<User>>
    {
        public SelectUserCommand() : base("SELECT u.Name, d.Name FROM Users u INNER JOIN Departments d ON u.DepartmentId = d.Id") { }


        public override List<User> ProcessDataReader(IDataReader rdr)
        {
            var users = new List<User>();

            while (rdr.Read())
            {
                var user = new User();
                user.Name = rdr[0].ToString();
                user.Department = new Department();
                user.Department.Name = rdr[1].ToString();
                users.Add(user);
            }
            return users;
        }
    }
}